package com.tom.jmgd.controller;


import com.tom.jmgd.core.entity.ResultEntity;
import com.tom.jmgd.core.enums.ResultEnum;
import com.tom.jmgd.dao.TCjLxWareMapper;
import com.tom.jmgd.dao.TLxCallbackLogMapper;
import com.tom.jmgd.dao.huobanSyncDataDao;
import com.tom.jmgd.entity.param.TLxCallbackLog;
import com.tom.jmgd.service.DzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;


@CrossOrigin
@RestController
@RequestMapping("/dz")
public class DzController {
    @Autowired
    TLxCallbackLogMapper tLxCallbackLogMapper;

    @Autowired
    DzService dzService;


    @Autowired
    TCjLxWareMapper tCjLxWareMapper;


    @PostMapping("/callBack")
    public ResultEntity callBack(@RequestBody Object object) {
        TLxCallbackLog tLxCallbackLog = new TLxCallbackLog();
        tLxCallbackLog.setJsondata(object.toString());
        tLxCallbackLog.setCreatedate(new Date());
        tLxCallbackLog.setCompname("大众");
        tLxCallbackLogMapper.insert(tLxCallbackLog);
        return new ResultEntity(ResultEnum.SUCCESS,null);
    }

    @RequestMapping("/queryPrice")
    public ResultEntity queryPrice(@RequestParam(value = "goodsid") String goodsid) throws Exception {
        return new ResultEntity(ResultEnum.SUCCESS,dzService.queryPrice(goodsid));
    }

    @RequestMapping("/queryPriceBatch")
    public ResultEntity queryPriceBatch() throws Exception {
        tCjLxWareMapper.selectList(null);
        //huobanSyncDataDao3.getSynTableName();
        return new ResultEntity(ResultEnum.SUCCESS,null);
    }

    @RequestMapping("/queryStock")
    public ResultEntity queryStock(@RequestParam(value = "goodsid") String goodsid) throws Exception {
        return new ResultEntity(ResultEnum.SUCCESS,dzService.queryStock(goodsid));
    }

    @RequestMapping("/createOrder")
    public ResultEntity createOrder(@RequestParam(value = "goodsid") String goodsid,
                                    @RequestParam(value = "remark") String remark,
                                    @RequestParam(value = "qty") int qty,
                                    @RequestParam(value = "price") BigDecimal price,
                                    @RequestParam(value = "paymethod") String paymethod) throws Exception {
        return new ResultEntity(ResultEnum.SUCCESS,dzService.createOrder(paymethod,remark,qty,price,goodsid));
    }

    @RequestMapping("/queryOrderStatus")
    public ResultEntity queryOrderStatus(@RequestParam(value = "orderCode") String orderCode) throws Exception {
        return new ResultEntity(ResultEnum.SUCCESS,dzService.queryOrderStatus(orderCode));
    }


}
